#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([TubeMan], [0.1], [odg@riseup.net], ,
        [https://notabug.org/odg/tubeman])
AM_INIT_AUTOMAKE([subdir-objects -Wall std-options])
AM_SILENT_RULES([yes])
AC_CONFIG_SRCDIR([src/tubeman.c])
AX_CHECK_ENABLE_DEBUG([no])

# Checks for programs
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_SED
AC_CANONICAL_HOST

# Gettext
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.19.8])

# Warning/Error flags
AX_CFLAGS_WARN_ALL
AX_APPEND_COMPILE_FLAGS([-Wextra -pedantic-errors])
AX_COMPILER_FLAGS

# Checks for dependency libraries
AX_LIB_CURL(,,AC_MSG_ERROR([missing libcurl]))
AX_LIB_SQLITE3()
AM_PATH_GTK_3_0

# Options
AC_ARG_ENABLE([tui],
AS_HELP_STRING([--disable-tui], [Build without the curses-based TUI]),
[AS_CASE([$enableval],
  [yes], [tui=true],
  [no],  [tui=false],
  [AC_MSG_ERROR([bad value ${enableval} for --enable-tui])]
)],
[tui=true])
AM_CONDITIONAL([TUI], [test x$tui = xtrue])
AM_COND_IF([TUI],
           [AX_WITH_CURSES
            AC_CHECK_LIB([menu], [new_menu], AC_SUBST([MENU_LIBS], [-lmenu])
                                             AC_DEFINE([HAVE_LIBMENU]))],
           [AC_DEFINE([NOTUI])])

# Checks for header files
#  ANSI C headers
AC_CHECK_HEADERS_ONCE([stdio.h stdarg.h stdlib.h string.h errno.h time.h])
#  POSIX headers
AC_CHECK_HEADERS_ONCE([unistd.h   pwd.h
                       sys/stat.h sys/types.h
                       sys/wait.h sys/ioctl.h])
#  Windows headers
AS_IF([test "x$host_os" = "xmingw*" || test "x$host_os" = "xcygwin*"],
  [AC_CHECK_HEADERS([windows.h direct.h])]
)
AC_CHECK_HEADERS([getopt.h], , [NOGETOPT=1])
AM_CONDITIONAL([NOGETOPT], [test "$NOGETOPT" = 1])

# Checks for typedefs, structures, and compiler characteristics
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_TYPE_UID_T
AC_C_CONST
AX_GCC_FUNC_ATTRIBUTE(unused)

# Checks for library functions
AX_FUNC_MKDIR
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([strchr strstr strtol strdup strndup])

AC_CONFIG_FILES([makefile src/makefile gtk/makefile po/Makefile.in])
AC_OUTPUT
